home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2.sit
/
Raven 1.2
/
Source
/
Foundation
/
Common
/
ZAllocator.h
< prev
next >
Wrap
Text File
|
1997-06-17
|
3KB
|
110 lines
/*
* File: ZAllocator.h
* Summary: Abstract base class for dynamic memory allocators.
* Written by: Jesse Jones
*
* Copyright ゥ 1997 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 1/29/97 JDJ Created
*/
#pragma once
#include <New.h>
#include <ZDebug.h>
#include <ZTypes.h>
//-----------------------------------
// Forward References
//
class TFixedAllocator;
class ZSizeDistribution;
//-----------------------------------
// Types
//
typedef void (*BlockValidateHook)(const void* block, long size, void* refCon);
// ===================================================================================
// class TAllocator
// ===================================================================================
class TAllocator {
//-----------------------------------
// Initialization/Destruction
//
public:
virtual ~TAllocator();
TAllocator();
private:
TAllocator(const TAllocator& rhs);
TAllocator& operator=(const TAllocator& rhs);
//-----------------------------------
// Allocations
//
public:
virtual void* Allocate(ulong bytes) = 0;
// Returns nil if allocation failed.
virtual void Deallocate(void* block) = 0;
//-----------------------------------
// Info
//
public:
// ----- Heap -----
virtual ulong GetHeapSize() const = 0;
virtual ulong GetPoolCount() const = 0;
// Returns the number of pools allocated (after the initial pool).
// ----- Blocks -----
virtual ulong GetBlockSize(const void* ptr) const = 0;
// Note that this may be slightly larger than the size passed to
// Allocate.
virtual ulong GetTotalBlockSize(const void* ptr) const = 0;
// Includes header and possibly trailer.
//-----------------------------------
// Debugging
//
public:
#if DEBUG
virtual void ValidateBlock(const void* ptr) const = 0;
virtual void ValidateHeap(BlockValidateHook hook = nil, void* refCon = nil) const = 0;
#endif
//-----------------------------------
// Internal API
//
public:
static void* operator new(size_t size);
// Allocators can be used by the global operator new so we'll
// take care of allocating ourselves.
static void operator delete(void* ptr);
#if DEBUG
static void TestAllocator(TAllocator& heap1, TAllocator& heap2, TAllocator& heap3);
// Runs some timing tests on the specified allocator.
protected:
static void DoTest(TAllocator& heap, const ZSizeDistribution& distribution);
#endif
};